package com.qf.zyh.web.controller;

import cn.dsna.util.images.ValidateCode;
import com.qf.zyh.common.Const;
import com.qf.zyh.util.StrUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/code")
public class CodeCont extends BaseServlet{
    public void getCode(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ValidateCode vc = new ValidateCode(120,30,4,30);
        request.getSession().setAttribute(Const.SysConst.VALI_CODE,vc.getCode());
        vc.write(response.getOutputStream());
    }
    public String CheckCode(HttpServletRequest request,HttpServletResponse response){
        String code = request.getParameter("code");
        String code1 = (String) request.getSession().getAttribute(Const.SysConst.VALI_CODE);
        //比较存储的验证码和驶入的验证码是否相同
        if (StrUtils.empty(code)&&code.equalsIgnoreCase(code1)){
            return Const.FAIL;
        }
        return Const.SUCCESS;
    }
}
